# 这是一个示例 Python 脚本。

# 按 Shift+F10 执行或将其替换为您的代码。
# 按 双击 Shift 在所有地方搜索类、文件、工具窗口、操作和设置。

import win32com.client as win32

def generate_email(recipient, cc_recipient,subject, body):
    outlook = win32.Dispatch('Outlook.Application')
    mail = outlook.CreateItem(0)
    mail.Subject = subject
    mail.Body = body
    mail.To = recipient
    mail.CC= cc_recipient
    # mail.To = ";".join(recipients)
    # mail.CC = ";".join(cc_recipients)
    mail.Send()

def save_email_to_draft(recipient,cc_recipient, subject, body):
    outlook = win32.Dispatch('Outlook.Application')
    mail = outlook.CreateItem(0)
    mail.Subject = subject
    mail.Body = body
    mail.To = recipient
    mail.CC = cc_recipient
    mail.Save()
    # mail.SaveAs(r"C:\Users\jimmy.tian\OneDrive - Veoneer\Desktop\email.msg")


def reply_to_email(email_subject, cc_recipient,reply_body):
    outlook = win32.Dispatch('Outlook.Application')
    namespace = outlook.GetNamespace("MAPI")
    inbox = namespace.GetDefaultFolder(6)  # 6 represents the Inbox folder
    # GetDefaultFolder()
    # 方法获取除收件箱以外的其他文件夹对象，您可以使用相应的参数来指定要获取的文件夹类型。以下是一些常见的文件夹类型及其对应的参数值：
    #
    # 收件箱（Inbox）：参数值为6
    # 发件箱（Sent
    # Items）：参数值为5
    # 草稿箱（Drafts）：参数值为16
    # 已删除项（Deleted
    # Items）：参数值为3
    # 日历（Calendar）：参数值为9
    # 联系人（Contacts）：参数值为10
    # 任务（Tasks）：参数值为13
    # 便签（Notes）：参数值为12
    # 遍历收件箱index文件夹中的邮件
    for item in inbox.Items:
        if item.Subject == email_subject:
            reply = item.Reply()  # 使用Reply()方法生成答复邮件
            reply.Body = reply_body
            reply.CC = cc_recipient
            reply.Send()
            break
# 输入数据relay
# email_subject = "邮件主题"
# reply_body = "这是我的答复"
# # 回复特定邮件
# reply_to_email(email_subject, reply_body)

# 输入数据generate
# recipients,cc_recipients变量是一个字符串，包含了需要抄送的收件人的电子邮件地址，多个收件人之间使用分号进行分隔
# recipient = "jimmy.tian1@magna.com"
# cc_recipient = "jimmy.tian1@magna.com"
# recipients = ["recipient1@example.com", "recipient2@example.com"]
# cc_recipients = ["cc1@example.com", "cc2@example.com"]
# subject = "邮件主题"
# body = "邮件正文"

# 生成邮件并发送
# generate_email(recipient, cc_recipient,subject, body)

# # 输入数据
# recipient = "jimmy.tian1@magna.com"
# cc_recipient = "jimmy.tian1@magna.com"
# subject = "邮件主题"
# body = "邮件正文"
#
# # 保存邮件到草稿箱
# save_email_to_draft(recipient, cc_recipient,subject, body)